#include<string.h>
#include<stdio.h>
#include<stdlib.h>
const char* symbols[] = {"M", "MC", "D", "DC", "C", "CX", "L", "LX", "X", "XI", "V", "VI", "I"};

char * intToRoman(int num);
int main()
{
    int x = 3888;
    printf("%s\n",intToRoman(x));
}
char * intToRoman(int num){
    int temp;
    char temp1;
    char* str = malloc(sizeof(char)*20);
    str[0] = '\0';
    int i = 1;
    while (num != 0)
    {
        temp = num % 10;
        num = num / 10;
        switch (i)
        {
            case 1:
            if (temp == 0)
            {
                ;
            }
            else if (temp >=1 && temp <=3)
            {
                while (temp != 0)
                {
                    strcpy(str+strlen(str),symbols[12]);
                    temp--;
                }
            }
            else if (temp == 4)
            {
                strcpy(str+strlen(str),symbols[11]);
            }
            else if (temp >=5 && temp <= 8)
            {
                while (temp != 5)
                {
                    strcpy(str+strlen(str),symbols[12]);
                    temp--;
                }
                strcpy(str+strlen(str),symbols[10]);
            }
            else
            {
                strcpy(str+strlen(str),symbols[9]);
            }
            break;

            case 2:
            if (temp == 0)
            {
                ;
            }
            else if (temp >=1 && temp <=3)
            {
                while (temp != 0)
                {
                    strcpy(str+strlen(str),symbols[8]);
                    temp--;
                }
            }
            else if (temp == 4)
            {
                strcpy(str+strlen(str),symbols[7]);
            }
            else if (temp >=5 && temp <= 8)
            {
                while (temp != 5)
                {
                    strcpy(str+strlen(str),symbols[8]);
                    temp--;
                }
                strcpy(str+strlen(str),symbols[6]);
            }
            else
            {
                strcpy(str+strlen(str),symbols[5]);
            }
            break;

            case 3:
            if (temp == 0)
            {
                ;
            }
            else if (temp >=1 && temp <=3)
            {
                while (temp != 0)
                {
                    strcpy(str+strlen(str),symbols[4]);
                    temp--;
                }
            }
            else if (temp == 4)
            {
                strcpy(str+strlen(str),symbols[3]);
            }
            else if (temp >=5 && temp <= 8)
            {
                while (temp != 5)
                {
                    strcpy(str+strlen(str),symbols[4]);
                    temp--;
                }
                strcpy(str+strlen(str),symbols[2]);
            }
            else
            {
                strcpy(str+strlen(str),symbols[1]);
            }
            break;

            case 4:
            if (temp == 0)
            {
                ;
            }
            else if (temp >=1 && temp <=3)
            {
                while (temp != 0)
                {
                    strcpy(str+strlen(str),symbols[0]);
                    temp--;
                }
            }
            break;
        }
        i++;
    }
    int len = strlen(str);
    for (int i = 0 , j = len - 1; i < j; i++,j--)
    {
        temp1 = str[i];
        str[i] = str[j];
        str[j] = temp1;
    }
    return str;
}